package com.nullpointer.xchatfinal.object;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

public class Nearby {
	private float distance;
	private User user;

	public Nearby() {
		super();
	}

	public Nearby(float distance, User user) {
		super();
		this.distance = distance;
		this.user = user;
	}

	public float getDistance() {
		return distance;
	}

	public void setDistance(float distance) {
		this.distance = distance;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String toJson() {
		return new JSONSerializer().exclude("*.class").deepSerialize(this);
	}

	public static Nearby fromJsonToNearby(String json) {
		return new JSONDeserializer<Nearby>().use(null, Nearby.class)
				.deserialize(json);
	}

	public static String toJsonArray(Collection<Nearby> collection) {
		return new JSONSerializer().exclude("*.class")
				.deepSerialize(collection);
	}

	public static Collection<Nearby> fromJsonArrayToNearbys(String json) {
		return new JSONDeserializer<List<Nearby>>().use(null, ArrayList.class)
				.use("values", Nearby.class).deserialize(json);
	}
}
